package com.danbay.cloud.lock.device.util;

/**
 * 设备-门锁通用操作工具类
 * @author yangyanchen on 2018/1/4
 *         Copyright © 2016 －2017 旦倍科技
 */
public class LockCommonUtils {

    private static final double VOLTAGE_FOUR_POINT_FIVE = 4.5;
    private static final double VOLTAGE_FOUR_SIX = 6;
    private static final String LOCK_LOW_POWER = "0";
    private static final String LOCK_HIGH_POWER = "100";

    /**
     * 计算门锁电表百分比
     * @param voltage
     * @return
     */
    public static String getLockElectricity(Integer voltage){
        if(voltage < VOLTAGE_FOUR_POINT_FIVE) {
            return LOCK_LOW_POWER;
        }else if(voltage > VOLTAGE_FOUR_POINT_FIVE) {
            return LOCK_HIGH_POWER;
        }else {
            int percent =(int)((voltage - 4.5) % 1.5 * 100);
            return String.valueOf(percent);
        }
    }
}
